package nirvana.core.domains.entity;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import jakarta.persistence.MappedSuperclass;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;

import java.sql.Timestamp;
import java.time.LocalDateTime;

/**
 * 审计基础类
 * 支持审计字段
 *
 * @param <T> Entity Type
 * @author linkanyway
 * @version 1.0
 * @date 2021/09/19 12:10
 */
@MappedSuperclass
@Data
@EqualsAndHashCode(callSuper = false)
public abstract class BaseAuditEntity<T extends Model<?>> extends BaseEntity<T> {
    /**
     * constructor
     */
    public BaseAuditEntity() {
    }


    /**
     * creator
     */
    @TableField(value = "creator", fill = FieldFill.INSERT)
    @Excel(name = "创建人", width = 15)
    @Column(type = MySqlTypeConstant.BIGINT,
            isNull = false,
            comment = "创建人")
    private Long creator;


    /**
     * create time
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    @Excel(name = "创建时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(type = MySqlTypeConstant.DATETIME,
            isNull = false,
            comment = "创建时间")
    private LocalDateTime createTime;


    /**
     * updater
     */
    @TableField(value = "updater", fill = FieldFill.INSERT_UPDATE)
    @Excel(name = "更新人", width = 15)
    @Column(type = MySqlTypeConstant.BIGINT,
            isNull = false,
            comment = "更新人")
    private Long updater;


    /**
     * latest update time
     */
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    @Excel(name = "更新时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(type = MySqlTypeConstant.DATETIME,
            isNull = false,
            comment = "更新时间")
    private LocalDateTime updateTime;


}
